package com.ruoyi.wechat.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.wechat.domain.Camp;
import com.ruoyi.wechat.domain.Message;
import com.ruoyi.wechat.mapper.CampMapper;
import com.ruoyi.wechat.mapper.MessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wechat.mapper.ProjectMapper;
import com.ruoyi.wechat.domain.Project;
import com.ruoyi.wechat.service.IProjectService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 营地项目Service业务层处理
 * 
 * @author jiang
 * @date 2024-11-24
 */
@Service
public class ProjectServiceImpl implements IProjectService 
{
    @Autowired
    private ProjectMapper projectMapper;
    @Resource
    private MessageMapper messageMapper;
    @Resource
    private CampMapper campMapper;

    /**
     * 查询营地项目
     * 
     * @param projectId 营地项目主键
     * @return 营地项目
     */
    @Override
    public Project selectProjectByProjectId(String projectId)
    {
        return projectMapper.selectProjectByProjectId(projectId);
    }

    /**
     * 查询营地项目列表
     * 
     * @param project 营地项目
     * @return 营地项目
     */
    @Override
    public List<Project> selectProjectList(Project project)
    {
        return projectMapper.selectProjectList(project);
    }

    /**
     * 新增营地项目
     * 
     * @param project 营地项目
     * @return 结果
     */
    @Override
    public int insertProject(Project project)
    {
        project.setProjectId(UUID.randomUUID().toString());
        return projectMapper.insertProject(project);
    }

    /**
     * 修改营地项目
     * 
     * @param project 营地项目
     * @return 结果
     */
    @Override
    public int updateProject(Project project)
    {
        return projectMapper.updateProject(project);
    }

    /**
     * 批量删除营地项目
     * 
     * @param projectIds 需要删除的营地项目主键
     * @return 结果
     */
    @Override
    public int deleteProjectByProjectIds(String[] projectIds)
    {
        return projectMapper.deleteProjectByProjectIds(projectIds);
    }

    /**
     * 删除营地项目信息
     * 
     * @param projectId 营地项目主键
     * @return 结果
     */
    @Override
    public int deleteProjectByProjectId(String projectId)
    {
        return projectMapper.deleteProjectByProjectId(projectId);
    }

    /**
     * 景点审核
     *1.消息表新增数据
     *2.修改项目表的审核状态
     * @param message 审核消息
     * @return 结果
     */
    @Transactional
    @Override
    public int approveProject(Message message) {
       //查询景点
        Project project = projectMapper.selectProjectByProjectId(message.getProjectId());
        //查询营地
        Camp camp = campMapper.selectCampByCampId(message.getCampId());
        //id
        message.setMessageId(UUID.randomUUID().toString());
        //审判时间
        message.setReleaseTime(new Date());
        //审核内容
        String content = message.getApprove().equals("1")?"审核通过，"+message.getContent():"审核失败，"+message.getContent();
        message.setContent("项目审核消息：“"+camp.getCampName()+"“营地的”"+project.getProjectName()+"“项目"+content);
        message.setUserId(camp.getUserId());
        messageMapper.insertMessage(message);
        //修改景点表的审核状态
        project.setApprove(message.getApprove());
        projectMapper.updateProject(project);
        return 1;
    }


}
